/**
 * RuleServiceImpl.java
 */
package com.prs.crm.service.document.rule.impl;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.document.rule.RuleDao;
import com.prs.crm.domain.document.knowledge.Doc;
import com.prs.crm.domain.document.rule.Rule;
import com.prs.crm.service.document.rule.RuleService;
import com.prs.crm.service.impl.BaseServiceImpl;

/**
 * @author ZhuDongMei
 * @E-mail:1223984339@qq.com
 * @qq:1223984339
 * @version 创建时间：2011-3-16 上午11:12:28 简单说明
 */
public class RuleServiceImpl extends BaseServiceImpl<Rule, RuleDao> implements
		RuleService {
	@Override
	public List<Rule> getAllRules() {
		// TODO Auto-generated method stub
		return this.getDao().getAllRules();
	}
	@Override
	public Collection<Rule> convertToRule(String ids) {
		try{
			Collection<Rule> rules = new ArrayList<Rule>();
			for(String id : ids.split(",")) {
				Rule rule = new Rule();
				rule.setId(Integer.valueOf(id));
				rules.add(rule);
			}
			return rules;
			}catch (NumberFormatException e) {
				e.printStackTrace();
				return null;
				}
	}
	@Override
	public Collection<Rule> getRootRule() {
		// TODO Auto-generated method stub
		return this.getDao().getRootRule();
	}
	@Override
	public Rule getRuleById(Serializable id) {
		// TODO Auto-generated method stub
		return this.getDao().getRuleById(id);
	}
	@Override
	public void saveRules(Rule rule, File file, String fileName) {
        Attach cAttach=FileUtil.getInstance().saveFile(file, fileName,"",Constrains.UPLOAD_DIR_RULE);
		
		if(cAttach.getSrc()!=null){
		//	rule.setDocument_file(cAttach.getSrc());
		}
		this.getDao().save(rule);
	}
	@Override
	public int removeRule(Integer id) {
		return this.getDao().removeRule(id);
	}
	
  
}
